home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / dtk_demo.zip / TIMEFORM.C < prev    next >
C/C++ Source or Header  |  1991-09-12  |  2KB  |  79 lines

  1. /*  TIMEFORM.C
  2.  *  last mod.: 10-AUG-91
  3.  */
  4.  
  5. /*  this displays a given time 27 times
  6.  *  using different time format parameters
  7.  */
  8.  
  9. #include <STDIO.H>
  10. #include <STDLIB.H>
  11. #include <STRING.H>
  12. #include <L_TIME.H>
  13. #include <L_STR.H>
  14.  
  15. char *usage = "\nUse TIMEFORM hour minute second hsecond\n";
  16. char time_str[32];
  17. Time t;
  18. Time_format tf;
  19. int n=0;
  20.  
  21. void main(int argc, char *argv[]);
  22. void display_time(void);
  23.  
  24. /*-----------------------------*/
  25. void main(int argc, char *argv[])
  26. {
  27. if ( argc < 3 )
  28.     {
  29.     printf(usage);
  30.     exit(0);
  31.     }
  32.  
  33. t.hour = (Uchar)atoi(argv[1]);
  34. t.minute = (Uchar)atoi(argv[2]);
  35. t.second = (Uchar)atoi(argv[3]);
  36. t.hsecond = (Uchar)atoi(argv[4]);
  37.  
  38. if ( !time_valid(&t) )
  39.     {
  40.     printf("\nInvalid time.\n");
  41.     exit(1);
  42.     }
  43.  
  44. set_time_format_default(&tf);
  45. for ( tf.components=0; tf.components<6; tf.components++ )
  46.     {
  47.     if ( tf.components >= 3 )
  48.         display_time();
  49.     else
  50.         {
  51.         for ( tf.hr_justified=FALSE; tf.hr_justified<=TRUE; tf.hr_justified++ )
  52.             {
  53.             for ( tf.style=0; tf.style<2; tf.style++ )
  54.                 {
  55.                 if ( tf.style==0 && tf.components <= 2 )
  56.                     {
  57.                     for ( tf.am_pm=0; tf.am_pm<3; tf.am_pm++ )
  58.                         display_time();
  59.                     }
  60.                 else
  61.                     display_time();
  62.                 }
  63.             }
  64.         }
  65.     }
  66. }
  67.  
  68. /*-------------------*/
  69. void display_time(void)
  70. {
  71. time_to_str(&t,&tf,time_str);
  72. pad_on_left(time_str,' ',19);
  73. printf("%s",time_str);
  74. if ( ++n%4 )
  75.     putchar(' ');
  76. else
  77.     putchar('\n');
  78. }
  79.